﻿using System;
//using System.Data;
using System.Configuration;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//using System.Xml.Linq;
//using System.Web.DynamicData;
using AjaxControlToolkit;
using System.Collections.Specialized;
using System.Collections.Generic;
using OrmAuto;

public partial class _Default : System.Web.UI.Page {

		protected string BaseUrl { get; set; } 
    
    protected void Page_Load(object sender, EventArgs e) 
    {
       //BaseUrl = "http://localhost:5139/myWebAuto.eu/" ;//Context.Request.ApplicationPath     ;  
       
        
    }//fM

				//protected override void InitializeCulture()
				//{
				//  //if (Request.Form["ListBox1"] != null)
				//  //{
				//  //  String selectedLanguage = Request.Form["ListBox1"];
				//  //  UICulture = selectedLanguage;
				//  //  Culture = selectedLanguage;

				//  //  Thread.CurrentThread.CurrentCulture =
				//  //      CultureInfo.CreateSpecificCulture(selectedLanguage);
				//  //  Thread.CurrentThread.CurrentUICulture = new
				//  //      CultureInfo(selectedLanguage);
				//  //}
				//  base.InitializeCulture();
				//}//fM


    [System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public static CascadingDropDownNameValue[] GetDropDownModelli(
                                string knownCategoryValues, string category)
    {
        var arrCatena = knownCategoryValues.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries);

        if (category.Equals("Modelli"))
        {
            if (arrCatena == null) return new CascadingDropDownNameValue[0];
            QuerierMarcheModelli mQuery = new QuerierMarcheModelli();

            var arr = arrCatena[0].Split(new[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
            //var idmarca = int.Parse(arr[1]);
            var marca = arr[1];
            int idMarca = 0;
            int.TryParse(marca, out idMarca);
            var modelli = mQuery.getModelli(idMarca).Select(
                    m => new CascadingDropDownNameValue() { name = m.Modello, value = m.ID.ToString() }).ToList();
            //modelli.Insert(0, new CascadingDropDownNameValue { isDefaultValue = false, name = "Tutti/All", value = "%%" });
            return modelli.ToArray();
        }

        return new CascadingDropDownNameValue[0];
    }//fM

				

}//fC
